export const AuthCheck = {
  methods: {
    checkLogin() {
      return this.$store.state.token !== null;
    },
    checkVerified() {
      return this.$store.state.verified == 1;
    }
  }
}

export const getBasicInfo = {
  computed: {
    getAvatar() {
      return this.$store.state.avatar;
    },
    getUid() {
      return this.$store.state.uid;
    },
    getUser() {
      return this.$store.state.user;
    },
    getCid() {
      if (this.$store.state.cid == null || this.$store.state.cid == 0)
        return 0;
      return this.$store.state.cid;
    }
  }
}

export const getDetailInfo = {
  data() {
    return {
      craftsman: null,
      user: null,
    }
  },
  beforeMount () {
    this.axios
      .get(`/api/user/${this.$store.state.uid}`)
      .then(res => (this.user = res.data))
      .catch(error => this.$Notice.error({
        title: '网络连接失败',
        desc: error
      }));

    if (this.$store.state.cid == null || this.$store.state.cid == 0)
      return;
    else
      this.axios
      .get(`/api/craftsman/${this.$store.state.cid}`)
      .then(res => (this.craftsman = res.data))
      .catch(error => this.$Notice.error({
        title: '网络连接失败',
        desc: error
      }));
  },
  mounted() {
    
  }
}

export const getUser = {
  data() {
    return {
      user: '',
    }
  },
  mounted() {
    this.axios
      .get(`/api/user/${this.$store.state.uid}`)
      .then(res => (this.user = res.data))
      .catch(error => this.$Notice.error({
        title: '网络连接失败',
        desc: error
      }));
  }
}
